#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：AutoMagic 
@File    ：handle_cookies.py
@Author  ：赵加响
@Date    ：2022/12/29 17:48 
@Desc    ：
"""
import json
import os

from contains import COOKIES_PATH


def save_cookies(data, cookie_type: str, encoding="utf-8"):
    """
    Cookies保存方法
    :param data:
    :param cookie_type:
    :param encoding:
    :return:
    """
    if not os.path.exists(COOKIES_PATH):
        os.mkdir(COOKIES_PATH)

    file_path = os.path.join(COOKIES_PATH, cookie_type.strip() + '.json')

    with open(file_path, "w", encoding=encoding) as f:
        json.dump(data, f)


def load_cookies(cookie_type: str, encoding="utf-8"):
    """
    Cookies读取方法
    :param cookie_type:
    :param encoding:
    :return:
    """
    file_path = os.path.join(COOKIES_PATH, cookie_type.strip() + '.json')
    with open(file_path, "r", encoding=encoding) as f:
        cookies = json.load(f)
    return cookies
